<template>
  <div class="page" :style="pageStyle">
    <slot name="bg" />

    <div
      class="headers"
      v-if="!$route.query.isApp"
      ref="header"
      :class="{ on: isheadBg }"
    >
      <slot name="header" />
    </div>

    <div
      class="content-container"
      id="scroll"
      :style="{
        paddingTop: head_height + 'px',
        paddingBottom: footer_height + 'px',
      }"
    >
      <div class="content-scroll" id="content">
        <slot name="content" />
      </div>
    </div>
    <div class="footer" v-if="footer" ref="footers">
      <slot name="footer" />
    </div>
    <slot />
  </div>
</template>
<script>
import { mapMutations } from "vuex";

export default {
  name: "PageScroll",
  props: {
    header: {
      type: Boolean,
      default: true,
    },
    headerFixed: {
      type: Boolean,
      default: false,
    },
    isheadBg: {
      type: Boolean,
      default: true,
    },

    pageStyle: {
      type: String,
      default: "",
    },
    footer: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isIOS: false,
      backTop: false,
      head_height: "",
      footer_height: "",
      timer: null,
    };
  },
  watch: {
    footHeight(a, b) {
      if (!this.footer) {
        this.footer_height = 0;
      } else {
        this.footer_height = this.footHeight;
      }
    },
  },
  created() {},
  computed: {
    headHeight() {
      return this.$store.state.headHeight;
    },
    footHeight() {
      return this.$store.state.footHeight;
    },
  },

  mounted() {
    let that = this;

    if (this.header) {
      this.timer = window.setInterval(() => {
        that.head_height = that.$refs.header?.offsetHeight;
        that.footer_height = that.$refs.footers?.offsetHeight;
      }, 500);
    }
  },

  destroyed() {
    clearTimeout(this.timer);
  },
  methods: {
    ...mapMutations(["SET_FOOTHeight", "SET_HEADHeight"]),
  },
};
</script>
<style lang="less" scoped>
.page {
  //position: absolute;
  //width: 100%;
  min-height: 100vh;
  //display: flex;
  //flex-direction: column;
  background-size: cover;

  .headers {
    position: fixed;
    top: 0;
    width: 100%;
    max-width: 8.5rem;
    z-index: 100;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
    -ms-transition: all 0.5s;
    -o-transition: all 0.5s;
    transition: all 0.5s;
    &.on {
    }
    &.fixed {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
    }
  }

  .footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    max-width: 8.5rem;
    z-index: 2;
  }

  .content-container {
    width: 100%;
    position: relative;
    flex-grow: 1;
    padding-top: 0.6rem;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
    -ms-transition: all 0.5s;
    -o-transition: all 0.5s;
    transition: all 0.5s;
    background-color: #151515;
    .content-scroll {
      padding-bottom: 0.24rem;
      //position: absolute;
      //top: 0;
      //left: 0;
      //width: 100%;
      //height: 100%;
      //overflow-y: auto;
      //overflow-scrolling: touch
    }
  }

  .back-top {
    position: absolute;
    bottom: 3rem;
    right: 0.1rem;
    z-index: 99;
    width: 1.4rem;
    height: 1.6rem;
  }
}
</style>
